home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / gospeed.zip / SPEED.DOC < prev   
Text File  |  1990-05-28  |  7KB  |  141 lines

  1. Date: Fri 18 May 90 19:14:41
  2. From: tweten@prandtl.nas.nasa.gov
  3. Subject: overwriting the psp
  4.  
  5. From: djb@wjh12.harvard.edu (David J. Birnbaum)
  6.  
  7. >... if it isn't too much trouble, I'd be interested in taking a look
  8. >at the source for the tsrs you mention.
  9.  
  10. I've enclosed the source code for my simplest TSR for illustration of the
  11. following points:
  12.  
  13.     1.  By using the undocumented MS-DOS INT 21 function 52H, you can
  14. find the beginning of the chain of MS-DOS memory blocks.  Run that
  15. chain and you will find all environment and code blocks in the machine
  16. (see the code after "blkscn" and the data structure at
  17. "BLK_HDR_SEGMENT").
  18.  
  19.     This is a better way to find a previously installed copy of a TSR
  20. than is use of any MS-DOS interrupt such as the MicroSoft-recommended
  21. "multiplex interrupt", 25H.  Even if you use an interrupt MicroSoft has
  22. "reserved for user programs" all that means is that the inevitable
  23. collision will be with some third party's program rather than with
  24. MicroSoft's.
  25.  
  26.     If you run the list of memory blocks, you can string compare some
  27. portion of the block's contents with your own code.  If the string is
  28. long enough and if it matches, you can bet it is another copy of your
  29. TSR.  The most important considerations in selecting a "signature" to
  30. compare are to make sure that it is long enough and is unchanging.  The
  31. machine instructions in the resident portion of your program will do
  32. nicely.  Just be sure not to embed any variable data in the comparison
  33. range, or you'll never find it.
  34.  
  35.     The technique can be used for simple duplicate detection, or can be
  36. used to pass new parameters to the existing TSR without having to use
  37. interrupts and risk collisions (see all references to "sibling").
  38.  
  39.     2.    In a TSR, the non-resident code and data should be positioned
  40. at the end of the program, so their space can be surrendered at initial
  41. termination (see the code at "START" and "go").
  42.  
  43.     3.  You can deal with the changed addresses of code relocated into
  44. the tail end of the PSP by modifying CS (see all references to
  45. "res_offs") before entry to the code, so it compensates for the move.
  46. That requires that the code be originally assembled at a location an
  47. even multiple of 16 bytes away from its final destination in the PSP.
  48. The result may be the "waste" of a few bytes in the initial .COM image
  49. (range between "START" and "beg_pr"), but you don't care because no
  50. space is wasted after termination.
  51.  
  52.     Some care must be devoted to the segment registers.  In the included
  53. program, I simply told the assembler not to use any segment registers
  54. but CS (see assume directive after "_TEXT").  This works well if you
  55. have few instructions which use another segment register by default;
  56. MASM will automatically prefix any such instructions with a CS segment
  57. override.
  58.  
  59.     If there would otherwise be a lot of prefixes, it may be worthwhile
  60. to save and restore initial contents of some other segment registers,
  61. and give them new values derived from CS.  If you do so, be sure to
  62. reflect that fact in your "assume" directive.
  63.  
  64. I hope all this helps.  Good luck.
  65.  
  66. ----------------------------8<--- CUT HERE ---8<--------------------------
  67.     page    58,132
  68.     TITLE    Go -- Control (and measure) speed for Heath/Zenith PC
  69.  
  70. ;    (c) Copyright 1987 David E. Tweten
  71.  
  72. ;    All rights reserved.  Permission for distribution is granted
  73. ;    provided that no direct commercial advantage is gained, and
  74. ;    provided that this copyright notice appears on all copies.
  75.  
  76. ;    --------------------------------------------------------------------
  77. ;
  78. ;    Go serves three purposes relating to Dante Bencivengo's "TurboPlus
  79. ;    V2.0" modification to 4.77 MHz Heath/Zenith PCs.  It permits FORMAT
  80. ;    and VERIFY ON to work.  It also permits the user to speed or slow
  81. ;    the processor.  Finally, it measures the processor's speed setting
  82. ;    (primarily for batch file use).  "TurboPlus", the predecessor
  83. ;    version of "TurboPlus V2.0", was described in the June, 1986 issue
  84. ;    of REMark, the journal of the Heath/Zenith Users' Group. 
  85. ;
  86. ;    Due to a quirk in the diskette BIOS, errors will occur when a track
  87. ;    format or verify operation is requested at any high speed, or when
  88. ;    any diskette operation is attempted at 8 MHz.  The terminate-and-
  89. ;    stay-resident portion of this code will prevent the errors from
  90. ;    occuring by slowing the processor for the duration of the
  91. ;    operation, unless it is already operating at the slow (4.77 MHz)
  92. ;    speed.
  93. ;
  94. ;    The optional switch for Go can specify the speed to use when not
  95. ;    formatting or verifying a floppy disk.  It can be "f", which will
  96. ;    set the clock speed to fast, or it can be "s", which will set the
  97. ;    clock speed to slow.  In any but its initial (TSR installing) call,
  98. ;    if no switch is given, Go does not change the speed setting.  On
  99. ;    the initial call, if no argument is given, Go assumes "f".  Go uses
  100. ;    whatever switch character is current.
  101. ;
  102. ;    The termination code for Go is set according to the processor speed
  103. ;    at call, and by whether or not it has previously been called.  The
  104. ;    meaning of its termination code is as follows:
  105. ;
  106. ;         0 - Go has been called before so the TSR portion is already
  107. ;             resident.  Before the call the clock was set to run at
  108. ;             4.77 MHz.
  109. ;
  110. ;         1 - Go has been called before so the TSR portion is already
  111. ;             resident.  Before the call the clock was set to run at
  112. ;             its fast speed.
  113. ;
  114. ;         2 - Go has not been called before.  This call installed the TSR
  115. ;             code and set the clock speed to the specified value (either
  116. ;             Fast or Slow).  If no speed was specified on the call, the
  117. ;             default of Fast was used.
  118. ;
  119. ;         3 - Go has been called in error.  It did nothing.
  120. ;
  121. ;    NOTE that the actual processor speed is the slower of the speed
  122. ;    specified and detected by Go, and the speed specified by the
  123. ;    hardware switch included in the "TurboPlus V2.0".  The actual speed
  124. ;    is indicated by the LED included with the "TurboPlus V2.0" package. 
  125. ;
  126. ;    Written by:  David E. Tweten   <tweten@prandtl.nas.nasa.gov>
  127. ;
  128. ;                                   12141 Atrium Drive
  129. ;                                   Saratoga, CA  95070
  130. ;
  131. ;                                   (408) 446-4131
  132. ;
  133. ;    Inspiration: FV.COM, a program of unstated authorship, included on
  134. ;                 the "TurboPlus" software disk.
  135. ;
  136. ;    Modification History:
  137. ;
  138. ;       1.0      5-10-87  Initial version.
  139. ;
  140. ;    --------------------------------------------------------------------
  141.